//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package common;

import java.io.UnsupportedEncodingException;

public class RC4 {
    int i;
    int j;
    byte[] s = new byte[256];

    private void init(byte[] key) {
        int size = key.length;
        if(size >= 1) {
            for(int t = 0; t < 256; ++t) {
                this.s[t] = (byte)t;
            }

            this.j = 0;

            for(this.i = 0; this.i < 256; ++this.i) {
                this.j = this.j + this.s[this.i] + key[this.i % size] & 255;
                this.swap(this.i, this.j);
            }

            for(this.i = this.j = 0; size != 0; --size) {
                this.i = this.i + 1 & 255;
                this.j = this.j + this.s[this.i] & 255;
                this.swap(this.j, this.i);
            }

        }
    }

    public RC4(byte[] k1, int offset1, int len1, byte[] k2, int offset2, int len2) {
        byte[] key = new byte[len1 + len2];
        System.arraycopy(k1, offset1, key, 0, len1);
        System.arraycopy(k2, offset2, key, len1, len2);
        this.init(key);
    }

    public RC4(String key1, String key2) {
        byte[] key;
        try {
            key = (key1 + key2).getBytes("US-ASCII");
        } catch (UnsupportedEncodingException var5) {
            var5.printStackTrace();
            return;
        }

        this.init(key);
    }

    void swap(int aIdx, int bIdx) {
        byte tmp = this.s[aIdx];
        this.s[aIdx] = this.s[bIdx];
        this.s[bIdx] = tmp;
    }

    private byte process(byte b) {
        this.i = this.i + 1 & 255;
        this.j = this.j + this.s[this.i] & 255;
        this.swap(this.i, this.j);
        byte tmp = this.s[this.s[this.i] + this.s[this.j] & 255];
        return (byte)(tmp ^ b);
    }

    public void process(byte[] inout) {
        if(inout != null) {
            for(int z = 0; z < inout.length; ++z) {
                inout[z] = this.process(inout[z]);
            }

        }
    }
}
